#include<bits/stdc++.h>
#define int long long
#define ls(x) ((x)*2)
#define rs(x) ((x)*2+1)
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define For(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define Rof(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define rep(i,  b) for(int i=1,i##end=b;i<=i##end;i++)
using namespace std;
const int N=1e6+5,base=999983,Mod=998244353;
//char buf[(1<<21)+5],*p1,*p2;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline void chmx(int &x,int y){(x<y)&&(x=y);}
inline void chmn(int &x,int y){(x>y)&&(x=y);}
inline void Add(int &x,int y){(x=x+y+Mod)%=Mod;}
inline int read(){
	int f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return f?-x:x;
}
void print(int n){
    if(n<0){
        putchar('-');
        n*=-1;
    }
    if(n>9) print(n/10);
    putchar(n%10+'0');
}
int k,m;
char s[N]; 
int Q,l[N],r[N],x[N];
string dfs(int L,int R,int p){
//	cout<<L<<" "<<R<<" "<<p<<endl;
	if(p==0){
		string t;
		For(i,L,R){
			t=t+s[i];
		}
		return t;
	}
	int len=r[p]-l[p]+1;
	if(x[p]+1+len<L){return dfs(L-len,R-len,p-1);}
	if(x[p]>=R){return dfs(L,R,p-1);}
	int ll=x[p]+1,rr=x[p]+len;
	if(L<ll&&R>rr){
		return dfs(L,ll-1,p-1)+dfs(l[p],r[p],p-1)+dfs(rr+1-len,R-len,p-1);
	}
	if(L<ll&&R<=rr){
		return dfs(L,ll-1,p-1)+dfs(l[p],r[p]-(rr-R),p-1);
	}
	if(L>=ll&&R>rr){
		return dfs(l[p]+(L-ll),r[p],p-1)+dfs(rr+1-len,R-len,p-1);
	}
	return dfs(l[p]+(L-ll),r[p]-(rr-R),p-1);
}
signed main(){
	freopen("copy.in","r",stdin);
	freopen("copy.out","w",stdout);
	// ios::sync_with_stdio(false);
	// cin.tie(0); cout.tie(0);
	k=read(),m=read();
	scanf("%s",s+1);Q=read();
	For(i,1,Q)l[i]=read()+1,r[i]=read(),x[i]=read();
	cout<<dfs(1,k,Q)<<endl;
#ifdef LOCAL
    Debug("\nMy Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0; 
}

